var searchParams;
	$(function() {
		//添加按钮事件
		$('#adddining').on('click', function() {
			var node=businessTable.datagrid('getSelected');
			if (node) {
				adddining(node.businessId);
			} else {
				layer.msg('请选择一条商家！', {
					time : 1000
				})
			}
		});
		//修改按钮事件
		$('#editdining').on('click', function() {
			var node = diningTable.datagrid('getSelected');
			if (node) {
				editdining(node.diningId);
			} else {
				layer.msg('请选择一条数据！', {
					time : 1000
				})
			}
		});
		//删除按钮事件
		$('#deldining').on('click', function() {
			deldining();
		});
		//查询按钮事件
		$('#searchdining').on('click', function() {
			searchdining();
		});
		//桌牌打包下载
		$('#zipdining').on('click', function() {
			var node=businessTable.datagrid('getSelected');
			if (node) {
				window.location.href=rootpath+'/hhDining/zipDining.do?businessId='+node.businessId;
			} else {
				layer.msg('请选择一条商家！', {
					time : 1000
				})
			}
		});
		//修改桌牌样式
		$('#diningStyle').on('click', function() {
			var businessId;
			var node=businessTable.datagrid('getSelected');
			if (node) {
				businessId=node.businessId;
				layer.open({
					title : '新增',
					type : 2,
					btn : [ '保存', '关闭' ],
					yes : function(index, layero) {
						var iframeWin =window[layero.find('iframe')[0]['name']];
						iframeWin.parentIframeName = window.name;
						iframeWin.$("#dataForm").submit();
						layer.close(index);
					},
					btn2 : function(index, layero) {
					},
					area : [ '80%', '80%' ],
					content : rootpath + '/hhDiningStyle/toStyleList.do?businessId=' + businessId
				});
			} else {
				layer.msg('请选择一条商家！', {
					time : 1000
				})
			}
		});
	});
	//Table表格数据源
	var diningTable = $('#dining_table').datagrid(BasicData.createDatagrid({
		url : '',
		checkOnSelect : true,
		singleSelect : true,
		selectOnCheck : true,
		frozenColumns : [ [ {
			field : 'ck',
			checkbox : true
		}, {
			title : 'diningId',
			field : 'diningId',
			hidden : true
		} ] ],
		columns : [ [   { field : 'name', title : '名称', width : '14%', sortable : true, align : 'center' },
			{
			field : 'note',
			title : '说明',
			width : '14%',
			sortable : true,
			align : 'center'
		},  {
			field : 'img',
			title : '二维码',
			width : '15%',
			sortable : true,
			align : 'center',
			formatter : function(value, row, index) {
				return '<img height="36" width="36" style="cursor: pointer;border: 1px solid #AAA;padding: 2px;background-color: #FFF;margin-right: 2px;" onclick="showPic(this);" src="' +imgPath+ value + '" />';
			}
		} ] ],
		onDblClickRow:function(rowIndex, rowData){
		
		},
		 onClickRow : function(index, row){

		 }
	}));
	//打开查询窗体
	function searchdining() {
		layer.open({
			title : '查询条件',
			type : 2,
			btn : [ '查询', '重置' ],
			yes : function(index, layero) {
				var iframeWin = window[layero.find('iframe')[0]['name']];
				searchParams = iframeWin.$("#searchForm").serialize();
				var newparam = iframeWin.$("#searchForm").serializeJSON();
				iframeWin.parentIframeName = window.name;
				$.extend(newparam, diningTable.queryParams);
				$('#dining_table').datagrid('load', newparam);
				layer.close(index);
			},
			btn2 : function(index, layero) {
				var iframeWin = window[layero.find('iframe')[0]['name']];
				iframeWin.parentIframeName = window.name;
				iframeWin.$("#searchForm").form("clear");
				return false;
			},
			area : [ '80%', '80%' ],
			content : rootpath + '/hhDining/toSearch.do?' + searchParams
		});
	}
	//添加打开窗体
	function adddining(businessId) {
		layer.open({
			title : '新增',
			type : 2,
			btn : [ '保存', '关闭' ],
			yes : function(index, layero) {
				var iframeWin =window[layero.find('iframe')[0]['name']];
				iframeWin.parentIframeName = window.name;
				iframeWin.$("#dataForm").submit();
			},
			btn2 : function(index, layero) {
			},
			area : [ '80%', '80%' ],
			content : rootpath + '/hhDining/toEdit.do?businessId=' + businessId
		});
	}
	//编辑打开窗体
	function editdining(diningId) {
		layer.open({
			title : '信息',
			type : 2,
			btn : [ '保存', '关闭' ],
			yes : function(index, layero) {
				var iframeWin = window[layero.find('iframe')[0]['name']];
				iframeWin.parentIframeName = window.name;
				iframeWin.$("#dataForm").submit();
			},
			btn2 : function(index, layero) {
			},
			area : [ '80%', '80%' ],
			content : rootpath + '/hhDining/toEdit.do?diningId=' + diningId
		});
	}
	//禁用
	function deldining(){
		var node = diningTable.datagrid('getSelected');
		if (node) {
			layer.confirm('您确定要删除桌牌'+node.name+'吗？', {
				btn : [ '确定', '取消' ]
			// 按钮
			}, function() {
				//$.uitools.showLoading();// 打开处理中遮罩层
				$.ajax({
					cache : true,
					type : "POST",
					url : rootpath + '/hhDining/delete.do',
					data : {
						diningId : node.diningId
					},
					async : false,
					success : function(data) {
						layer.msg('成功！', {
							icon : 1,
							time : 1000
						}, function() {
							//刷新列表
							diningTable.datagrid('reload');
						})
					}
				});
			}, function() {
			});
		}else {
			layer.msg('请选择一条数据！', {
				time : 1000
			})
		}
	}
	
	function showPic(photo) {
		var img = $(photo);
		var photos = {
			"title" : "", //相册标题
			"start" : 0, //初始显示的图片序号，默认0
			"data" : [ //相册包含的图片，数组格式
			{
				"alt" : "图片",
				//原图地址
				"src" : $(photo)[0].src

			} ]
		};
		layer.photos({
			photos : photos,
			//0-6的选择，指定弹出图片动画类型，默认随机
			anim : 5

		});
	}